package com.yong.ssj.control.admin.customer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.yong.ssj.db.dto.customer.CustomerDto;
import com.yong.ssj.db.dto.customer.MaterialDto;
import com.yong.ssj.service.customer.IOrdinaryService;
import com.yong.ssj.vo.customer.MaterialVo;
import com.yong.ssj.vo.customer.UpdategerenVo;
import com.yong.ssj.vo.customer.UpdatejiaVo;

@Controller
@RequestMapping("/admin/customer")
public class CustomerController {
	@Resource(name="OrdinaryServiceImpl")
	private IOrdinaryService ordinaryService;
	
	@RequestMapping("ordinary")
	public String customerList(ModelMap rps){//初始查找
		List<Map<String, Object>> list = ordinaryService.queryOrdinary();
		rps.put("customerList", list);
		return "admin/customer/ordinary";
	}
	
	@RequestMapping(value = "ordinary_query", method = { RequestMethod.POST, RequestMethod.GET })
	public String customer(ModelMap rps,@RequestParam String phone){//根据手机号查找
		CustomerDto dto = ordinaryService.queryCustomer(phone);
		List<CustomerDto> list = new ArrayList<CustomerDto>();
		list.add(dto);
		rps.put("customerList", list);
		return "admin/customer/ordinary";
	}
	
	@RequestMapping("/query_ord/{customer_id}")
	public String material(ModelMap rps,@PathVariable String customer_id){//查询详情
		CustomerDto vo = ordinaryService.queryCus(Long.parseLong(customer_id));
		rps.put("material", vo);
		return "admin/customer/query_ord";
	}
	
	@RequestMapping("wait")
	public String waitList(ModelMap rps){//查找未认证用户
		List<Map<String, Object>> list = ordinaryService.queryWait();
		rps.put("customerList", list);
		return "admin/customer/wait";
	}
	
	@RequestMapping(value = "wait_query", method = { RequestMethod.POST, RequestMethod.GET })
	public String waitList(ModelMap rps,@RequestParam String phone){//根据手机号查找
		CustomerDto dto = ordinaryService.queryCustomer(phone);
		List<CustomerDto> list = new ArrayList<CustomerDto>();
		list.add(dto);
		rps.put("customerList", list);
		return "admin/customer/wait";
	}
	
	@RequestMapping("/wait_query_ord/{customer_id}")
	public String waitMaterial(ModelMap rps,@PathVariable String customer_id){//查询详情
		MaterialVo vo = ordinaryService.queryDetails(customer_id);
		rps.put("material", vo);
		return "admin/customer/wait_query_ord";
	}
	
	
	@RequestMapping("wait_update_geren")
	public String updateCustomergr(UpdategerenVo vo,HttpServletRequest request){//审核身份证版
		int yan = ordinaryService.updateGeren(vo);
		return "forward:/admin/customer/wait";
	}
	
	@RequestMapping("wait_update_jiashi")
	public String updateCustomerjs(UpdatejiaVo vo,HttpServletRequest request){//审核驾驶版
		int yan = ordinaryService.updateJS(vo);
		return "forward:/admin/customer/wait";
	}
	
	@RequestMapping("authenticated")
	public String authenticated(ModelMap rps){//查找已认证的用户
		List<Map<String, Object>> list = ordinaryService.queryAuthe();
		rps.put("customerList", list);
		return "admin/customer/authenticated";
	}
	
	@RequestMapping(value = "authenticated_query", method = { RequestMethod.POST, RequestMethod.GET })
	public String auList(ModelMap rps,@RequestParam String phone){//根据手机号查找
		CustomerDto dto = ordinaryService.queryCustomer(phone);
		List<CustomerDto> list = new ArrayList<CustomerDto>();
		list.add(dto);
		rps.put("customerList", list);
		return "admin/customer/authenticated";
	}
	@RequestMapping("/au_query_ord/{customer_id}")
	public String quMaterial(ModelMap rps,@PathVariable String customer_id){//查询详情
		MaterialVo vo = ordinaryService.queryDetails(customer_id);
		rps.put("material", vo);
		return "admin/customer/au_query_ord";
	}
}
